import type { Metadata } from "next";
import { Inter } from "next/font/google";
import "./globals.css";
import "antd/dist/reset.css";
import "@/styles/wangeditor.css";
import AntdProvider from "@/components/AntdProvider";
import DebugProvider from "@/components/DebugProvider";

export const dynamic = "force-dynamic";

const inter = Inter({ subsets: ["latin"] });

const siteDescription = "AI产品之家是一个聚焦AI产品的社区，为用户提供AI产品的评测分析和使用案例，帮助用户便捷找到合适的AI产品、轻松用好AI产品，同时为AI产品经理和开发者提供线上交流平台，共同打造优质的AI产品。";

export const metadata: Metadata = {
  title: {
    template: "%s - AI产品之家",
    default: "AI产品之家 - 做好AI产品，用好AI产品",
  },
  description: siteDescription,
  keywords: ["AI产品", "人工智能", "AI工具", "AI应用", "AI攻略", "机器学习", "深度学习", "自然语言处理", "计算机视觉", "AI助手", "AI绘画", "AI视频", "AI音乐", "AI编程"],
  authors: [{ name: "AI产品之家" }],
  creator: "AI产品之家",
  publisher: "AI产品之家",
  formatDetection: {
    email: false,
    address: false,
    telephone: false,
  },
  metadataBase: new URL("http://aiproducthome.com"),
  alternates: {
    canonical: "/",
  },
  openGraph: {
    title: "AI产品之家 - 做好AI产品 用好AI产品",
    description: "AI产品之家是专业的AI产品发现平台，汇集最新的人工智能技术、工具和应用攻略。",
    url: "/",
    siteName: "AI产品之家",
    images: [
      {
        url: "/og-image.jpg",
        width: 1200,
        height: 630,
        alt: "AI产品之家",
      },
    ],
    locale: "zh_CN",
    type: "website",
  },
  twitter: {
    card: "summary_large_image",
    title: "AI产品之家 - 做好AI产品 用好AI产品",
    description: "AI产品之家是专业的AI产品发现平台，汇集最新的人工智能技术、工具和应用攻略。",
    images: ["/og-image.jpg"],
  },
  robots: {
    index: true,
    follow: true,
    googleBot: {
      index: true,
      follow: true,
      "max-video-preview": -1,
      "max-image-preview": "large",
      "max-snippet": -1,
    },
  },
  verification: {
    google: "your-google-verification-code",
  },
};

export default function RootLayout({ children }: { children: React.ReactNode }) {
  // 使用固定的站点 URL，避免服务端与客户端渲染不一致
  const siteUrl = "http://www.aiproducthome.com/";
  return (
    <html lang='zh-CN'>
      <head>
        {/* 结构化数据 */}
        <script
          suppressHydrationWarning
          type='application/ld+json'
          dangerouslySetInnerHTML={{
            __html: JSON.stringify({
              "@context": "https://schema.org",
              "@type": "WebSite",
              name: "AI产品之家",
              description: siteDescription,
              url: siteUrl,
              potentialAction: {
                "@type": "SearchAction",
                target: {
                  "@type": "EntryPoint",
                  urlTemplate: `${siteUrl}search?q={search_term_string}`,
                },
                "query-input": "required name=search_term_string",
              },
            }),
          }}
        />

        <style
          dangerouslySetInnerHTML={{
            __html: `
            /* 防止FOUC的初始样式 */
            body { 
              opacity: 0; 
              transition: opacity 0.3s ease-in-out;
            }
            body.loaded { 
              opacity: 1; 
            }
            /* 确保Ant Design样式优先加载 */
            .ant-app { 
              opacity: 1 !important; 
            }
          `,
          }}
        />
        <meta name='baidu-site-verification' content='codeva-vJFMmfc6C0' />
        <meta name='google-site-verification' content='kNUzKOObgchNEqkFlO9of5ZSwMIBudFeaTwuuKdbtzc' />
        <meta name='msvalidate.01' content='07DF65238CA0CE3FBA47F0F2190B65E8' />

        {/* Open Graph Meta Tags */}
        <meta property='og:title' content='AI产品之家 - 做好AI产品 用好AI产品' />
        <meta property='og:description' content={siteDescription} />
        <meta property='og:image' content='https://smms.app/image/Iy17PkHsu9AxQci' />
        <meta property='og:url' content={siteUrl} />

        {/* 微信专用标签（可选） */}
        <meta property='wechat:title' content='AI产品之家 - 做好AI产品 用好AI产品' />
        <meta property='wechat:description' content={siteDescription} />
        <meta property='wechat:image' content='https://smms.app/image/Iy17PkHsu9AxQci' />
        <meta property='wechat:url' content={siteUrl} />
      </head>
      <body className={inter.className}>
        <AntdProvider>
          <DebugProvider>
            {children}
          </DebugProvider>
        </AntdProvider>
        <script
          dangerouslySetInnerHTML={{
            __html: `
              var _hmt = _hmt || [];
              (function() {
                var hm = document.createElement("script");
                hm.src = "https://hm.baidu.com/hm.js?de50375477e4440e797068e1864cf6b8";
                var s = document.getElementsByTagName("script")[0];
                s.parentNode.insertBefore(hm, s);


                var hm2 = document.createElement("script");
                hm2.src = "https://hm.baidu.com/hm.js?1eca1e330c473a2ab4f65a7afb494da8";
                var s2 = document.getElementsByTagName("script")[0]; 
                s2.parentNode.insertBefore(hm2, s2);


                var hm3 = document.createElement("script");
                hm3.src = "https://hm.baidu.com/hm.js?98f962a07f22ccf9e733ea5d4a28d378";
                var s3 = document.getElementsByTagName("script")[0]; 
                s3.parentNode.insertBefore(hm3, s3);
              })();
             
            `,
          }}
        />
      </body>
    </html>
  );
}
